import {C} from "../utils";

let down = false
let mouse = {}
let lineWidth = 50

export default {
  click(){
    mouse = C.getOffset(this.canvas)
    let canvas = document.createElement('CANVAS')
    canvas.width = this.canvasRect.width
    canvas.height = this.canvasRect.height
    this.ctx2 = canvas.getContext('2d')
    this.ctx2.putImageData(this.imgDataOld, 0, 0)
  },
  canvasMousedown() {
    down = true
  },
  canvasMouseup(e) {},
  canvasMouseout(e) {},
  canvasTouchstart(e) {},
  canvasTouchend(e) {},
  winMouseup() {
    down = false
  },
  winMousemove() {
    if(down){
      let pxs = this.ctx2.getImageData(mouse.x * this.scale, mouse.y * this.scale, lineWidth, lineWidth);
      // 用于从撤销使用
      // let pxsOld = this.ctx.getImageData(mouse.x, mouse.y, lineWidth, lineWidth);
      this.ctx.putImageData(pxs, mouse.x * this.scale, mouse.y * this.scale);
      // 用于从撤销使用
      // this.ctx.putImageData(pxsOld, mouse.x, mouse.y);
    }
  },
  winTouchend() {
    down = false
  },
  visibilitychange() {}
}
